Repository navigation
fix(prebuilt): support generic type arguments for ToolRuntime injection - #6509
Sydney Runkle (sydney-runkle) merged 5 commits into
Conversation
|
Sidharth Rajmohan (@dumko2001) is attempting to deploy a commit to the LangChain Team on Vercel. A member of the Team first needs to authorize it. |
8abcea9 to
29f4d21
Compare
Sydney Runkle (sydney-runkle)
left a comment
There was a problem hiding this comment.
Thanks so much. This is consistent w/ the logic we have for checking the origin in langchain-core as well.
It's actually a bit odd that these functions aren't unified.
cb2faa7
into
langchain-ai:main
|
Hi Sidharth, I ran a real before-and-after test on this. First, I caught an error in my own notes. I had this PR's merge date wrong (I had 2025-11-27, which is actually when it was opened; it merged on 2026-01-12). I corrected this before testing. I installed real langgraph-prebuilt==1.0.5 (pre-fix) and 1.0.6 (post-fix, the actual first release with your fix). I then built a tool with a ToolRuntime[MyContext]-annotated parameter and dispatched it through a real ToolNode.invoke() call, running it 10 times for each version. The Results
I confirmed this at the source level as well. The _is_injection() function in 1.0.5 has no generic-origin branch, whereas 1.0.6 adds exactly the check needed for get_origin(ToolRuntime[MyContext]) to match. I maintain agent-eval (agent_regress). You can find the full scripts and raw output here: https://github.com/RudrenduPaul/agent-eval Given you are doing more ToolRuntime generic-type work, I am curious whether this reproduction matches the real-world case that prompted the fix, or if there is a related generic-type edge case worth testing next. Best, |
…on (langchain-ai#6509) **Description:** This PR fixes an issue where injection types (like `ToolRuntime`) were not recognized by `ToolNode` when used with generic type arguments (e.g., `ToolRuntime[MyContext]`). Previously, the `_is_injection` check relied solely on `isinstance` and `issubclass`, which fail for `typing._GenericAlias` objects. This update adds a check using `typing.get_origin()` to correctly identify the base class of generic types, ensuring the runtime is injected correctly even when type hints are present. **Issue:** Fixes langchain-ai#6465 **Dependencies:** None **Twitter handle:** @SidharthRajmoh2 --------- Co-authored-by: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com>
Description:
This PR fixes an issue where injection types (like
ToolRuntime) were not recognized byToolNodewhen used with generic type arguments (e.g.,ToolRuntime[MyContext]).Previously, the
_is_injectioncheck relied solely onisinstanceandissubclass, which fail fortyping._GenericAliasobjects. This update adds a check usingtyping.get_origin()to correctly identify the base class of generic types, ensuring the runtime is injected correctly even when type hints are present.Issue: Fixes #6465
Dependencies: None
Twitter handle: @SidharthRajmoh2